package com.jensen.service;

import com.jensen.dao.UserDao;
import com.jensen.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * Created by Jensen on 2016/9/30.
 */
@Service
@Transactional
public class UserService {
    @Autowired
    private UserDao userDao;

    public void test1(){
        this.userDao.save(new User(UUID.randomUUID().toString(),"xxx","yyy"));
        this.userDao.save(new User(UUID.randomUUID().toString(),"xxx","yyy"));
        this.userDao.save(new User(UUID.randomUUID().toString(),"xxx","yyy"));
        throw new RuntimeException();
    }

    public void test2() {
        String hql="update User set name='a' where id='1'";
        this.userDao.execByHql(hql);
        String sql="update user set user.name='b' where id='2'";
        this.userDao.execBySql(sql);
        System.out.println();
    }

    public void test3(){
        String hql="update User set name='a' where id='1'";
        this.userDao.execByHql(hql);
        this.userDao.save(new User(UUID.randomUUID().toString(),"xxx","yyy"));
        System.out.println();
        throw new RuntimeException();
    }
}
